<?php
class NewsController extends AdminBaseController {
	public function lists(){
		$nav_id = $_REQUEST['nav_id'];
		$where['nav_id'] = $nav_id;
		$where['recom_status']= $_REQUEST['recom_status'];
		$where['type']= $_REQUEST['type'];
		$where['pub_status']= $_REQUEST['pub_status'];
		$where['title']= $_REQUEST['title'];
		$data = HttpServerManager::getNewsServer()->paging($where);
		$news_class_list = HttpDaoManager::getNewsClassDao()->searchList();
		$news_class_pair = array();
		foreach($news_class_list as $key=>$value){
			$news_class_pair[$value['id']] = $value['title'];
		}
		$data['news_class_pair'] = $news_class_pair;
		$data['nav_id'] = $nav_id;
		
		$data['newsRecoStatus'] = Common::_t('news_reco_status');
		$data['newsType'] = Common::_t('news_type');
		$data['newsPubStatus'] = Common::_t('news_pub_status');
		
		$data['newsRecoStatusOption']  = page_modifier_options($data['newsRecoStatus'],Common::getGetStrValue('recom_status'));
		$data['newsTypeOption']  = page_modifier_options($data['newsType'],Common::getGetStrValue('type'));
		$data['newsPubStatusOption']  = page_modifier_options($data['newsPubStatus'],Common::getGetStrValue('pub_status'));
		return $data;
	}
	
	public function newsPublists(){
		$nav_id = $_REQUEST['nav_id'];
		$where['nav_id'] = $nav_id;
		$where['recom_status']= $_REQUEST['recom_status'];
		$where['type']= $_REQUEST['type'];
		$where['pub_status']= $_REQUEST['pub_status'];
		$where['title']= $_REQUEST['title'];
		$where['type'] = NEWS_PUB_TYPE_LIST;
		$data = HttpServerManager::getNewsServer()->paging($where);
		$news_class_list = HttpDaoManager::getNewsClassDao()->searchList();
		$news_class_pair = array();
		foreach($news_class_list as $key=>$value){
			$news_class_pair[$value['id']] = $value['title'];
		}
		$data['news_class_pair'] = $news_class_pair;
		$data['nav_id'] = $nav_id;
		
		$data['newsRecoStatus'] = Common::_t('news_reco_status');
		$data['newsType'] = Common::_t('news_type');
		$data['newsPubStatus'] = Common::_t('news_pub_status');
		
		$data['newsRecoStatusOption']  = page_modifier_options($data['newsRecoStatus'],Common::getGetStrValue('recom_status'));
		$data['newsTypeOption']  = page_modifier_options($data['newsType'],Common::getGetStrValue('type'));
		$data['newsPubStatusOption']  = page_modifier_options($data['newsPubStatus'],Common::getGetStrValue('pub_status'));


		$where = array();
		$where['father_id']=FRONT_INDEX_NAV;
		$top_nav_list = HttpDaoManager::getNavDao()->searchList($where);
		$top_child_nav_id_list = Common::array_value_list($top_nav_list, 'id');
		$where = array();
		$top_child_nav_id_list_str = implode(',',$top_child_nav_id_list);
		$where['father_id'] = array($top_child_nav_id_list_str,'in');
		$where['news_type'] = NEWS_PUB_TYPE_LIST;
		$where['news_status'] = 1 ;
		$child_nav_list =  HttpDaoManager::getNavDao()->searchList($where);
		$pub_nav_pair = array();
		foreach($child_nav_list as $key=>$value){
			$pub_nav_pair[$value['id']] = $value['title'];
		}
		$data['pub_nav_pair']= $pub_nav_pair;
		$data['newsPubnavOption']  = page_modifier_options($pub_nav_pair,$data['nav_id']);
		return $data;
	}
	
	
	public function newsPubSinglelists(){
		$nav_id = $_REQUEST['nav_id'];
		$where['nav_id'] = $nav_id;
		$where['recom_status']= $_REQUEST['recom_status'];
		$where['type']= $_REQUEST['type'];
		$where['pub_status']= $_REQUEST['pub_status'];
		$where['title']= $_REQUEST['title'];
		$where['type'] = NEWS_PUB_TYPE_SINGLE;
 		$data = HttpServerManager::getNewsServer()->paging($where);
		$news_class_list = HttpDaoManager::getNewsClassDao()->searchList();
		$news_class_pair = array();
		foreach($news_class_list as $key=>$value){
			$news_class_pair[$value['id']] = $value['title'];
		}
		$data['news_class_pair'] = $news_class_pair;
		$data['nav_id'] = $nav_id;
		
		$data['newsRecoStatus'] = Common::_t('news_reco_status');
		$data['newsType'] = Common::_t('news_type');
		$data['newsPubStatus'] = Common::_t('news_pub_status');
		
		$data['newsRecoStatusOption']  = page_modifier_options($data['newsRecoStatus'],Common::getGetStrValue('recom_status'));
		$data['newsTypeOption']  = page_modifier_options($data['newsType'],Common::getGetStrValue('type'));
		$data['newsPubStatusOption']  = page_modifier_options($data['newsPubStatus'],Common::getGetStrValue('pub_status'));
		
		$where = array();
		$where['father_id']=FRONT_INDEX_NAV;
		$top_nav_list = HttpDaoManager::getNavDao()->searchList($where);
		$top_child_nav_id_list = Common::array_value_list($top_nav_list, 'id');
		$where = array();
		$top_child_nav_id_list_str = implode(',',$top_child_nav_id_list);
		$where['father_id'] = array($top_child_nav_id_list_str,'in');
		$where['news_type'] = NEWS_PUB_TYPE_SINGLE;
		$where['news_status'] = 1 ;
		$child_nav_list =  HttpDaoManager::getNavDao()->searchList($where);
		$pub_nav_pair = array();
		foreach($child_nav_list as $key=>$value){
			$pub_nav_pair[$value['id']] = $value['title'];
		}
		$data['pub_nav_pair']= $pub_nav_pair;
		$data['newsPubnavOption']  = page_modifier_options($pub_nav_pair,$data['nav_id']);
		
		return $data;
	}
	
	public function add(){
		$data =  array();
		$nav_id = $_REQUEST['nav_id'];
		if (!empty($_GET['id'])){
			$data = HttpDaoManager::getNewsDao()->get($_GET['id']);
			$nav_id = $data['nav_id'];
		}
		$data['nav_id'] = $nav_id;
		$pub_type = $_REQUEST['pub_type'];
		if(isset($pub_type)&&$pub_type>0){
			if($pub_type==NEWS_PUB_TYPE_LIST){
				$where = array();
				$where['father_id']=FRONT_INDEX_NAV;
				$top_nav_list = HttpDaoManager::getNavDao()->searchList($where);
				$top_child_nav_id_list = Common::array_value_list($top_nav_list, 'id');
				$where = array();
				$top_child_nav_id_list_str = implode(',',$top_child_nav_id_list);
				$where['father_id'] = array($top_child_nav_id_list_str,'in');
				$where['news_type'] = $pub_type;
				$child_nav_list =  HttpDaoManager::getNavDao()->searchList($where);
				$pub_nav_pair = array();
				foreach($child_nav_list as $key=>$value){
					$pub_nav_pair[$value['id']] = $value['title'];
				}
				$data['pub_nav_pair']= $pub_nav_pair;
				$data['newsPubnavOption']  = page_modifier_options($pub_nav_pair,$data['nav_id']);
			}else{
				$nav = HttpDaoManager::getNavDao()->get($data['nav_id']);
				$pub_nav_pair = array();
				$pub_nav_pair[$nav['id']] = $nav['title'];  
				$data['pub_nav_pair']= $pub_nav_pair;
			}
		}
		//$data['pic'] = HttpServerManager::getUploadServer()->eosUploadShow('pic', Common::getStrValue($data, 'pic'));
		$ueditor = ClassManager::getUeditor();
		$data['ueditor'] = $ueditor->ueditor();
		$data['content'] = $ueditor->ueditors('content',Common::getStrValue($data, 'content'));
		$data['newsClass'] =  HttpServerManager::getNewsClassServer()->infiniteClass(array('id'=>0));
		$data['newsRecoStatus'] = Common::_t('news_reco_status');
		$data['newsType'] = Common::_t('news_type');
		$data['newsPubStatus'] = Common::_t('news_pub_status');
		$data['newsRecoStatusOption']  = page_modifier_options($data['newsRecoStatus'],$data['recom_status']);
		$data['newsTypeOption']  = page_modifier_options($data['newsType'],$data['type']);
		$data['newsPubStatusOption']  = page_modifier_options($data['newsPubStatus'],$data['pub_status']);
		return $data;
	}
	public function subAdd(){
		$nav_id=$_POST['nav_id'];
		$pub_type = $_REQUEST['pub_type'];
		$_POST['time']= time();
		HttpDaoManager::getNewsDao()->add($_POST);
		$url = 'news_lists.html?nav_id='.$nav_id;
		if(isset($pub_type)&&$pub_type>0){
			if($pub_type==NEWS_PUB_TYPE_SINGLE){
				$url = 'news_PubSinglelists.html';
			}else{
				$url = 'news_newsPublists.html';
			}
		}
		
		ClassManager::getToos()->msgbox('添加成功',$url);
	}
	public function subUpdate(){
		$nav_id=$_POST['nav_id'];
		$_POST['time']= time();
		$pub_type = $_REQUEST['pub_type'];
		HttpDaoManager::getNewsDao()->update($_POST,$_POST['id']);
		$url = 'news_lists.html?nav_id='.$nav_id;
		if(isset($pub_type)&&$pub_type>0){
			if($pub_type==NEWS_PUB_TYPE_SINGLE){
				$url = 'news_newsPubSinglelists.html';
			}else{
				$url = 'news_newsPublists.html';
			}
		}	
		ClassManager::getToos()->msgbox('修改成功',$url);
	}
	public function delete(){
		HttpServerManager::getNewsServer()->deleteBatchByid($_GET['id']);
		ClassManager::getToos()->msgbox("删除成功");
	}

}
?>